package com.schoolvisitors.converter;

import com.schoolvisitors.enums.GenderEnum;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter(autoApply = true)
public class GenderEnumConverter implements AttributeConverter<GenderEnum, Byte> {

    @Override
    public Byte convertToDatabaseColumn(GenderEnum gender) {
        return gender != null ? gender.getCode() : null;
    }

    @Override
    public GenderEnum convertToEntityAttribute(Byte dbData) {
        return dbData != null ? GenderEnum.fromCode(dbData) : null;
    }
}
